package servlet;

import dao.CourseDao;
import bean.User;
import bean.Course;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletDeleteCourse extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        Course course = new Course();
        course.setId(id);
        // 获取当前用户
        User user = (User)req.getSession().getAttribute("user");

        // 删除数据
        new CourseDao().delete(course,user);

        resp.sendRedirect("index");
    }
}
